using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DTO
{
	/// <summary> 
	///Author: nnamthach@gmail.com 
	/// <summary>
	
    public class UserInfo
    {
		#region Local Variable
		public enum Field
		{
			ID,
			Email,
			Password,
			FirstName,
			LastName,
			Address1,
			Address2,
			CompanyName,
			Mobile,
			District,
			City,
			Country,
			Sex,
			Score,
			Postcode
		}
		private Int32 _ID;
		private String _Email;
		private String _Password;
		private String _FirstName;
		private String _LastName;
		private String _Address1;
		private String _Address2;
		private String _CompanyName;
		private String _Mobile;
		private String _District;
		private String _City;
		private String _Country;
		private String _Sex;
		private Int32 _Score;
		private String _Postcode;
		
		public Int32 ID{	get{ return _ID;} set{_ID = value;} }
		public String Email{	get{ return _Email;} set{_Email = value;} }
		public String Password{	get{ return _Password;} set{_Password = value;} }
		public String FirstName{	get{ return _FirstName;} set{_FirstName = value;} }
		public String LastName{	get{ return _LastName;} set{_LastName = value;} }
		public String Address1{	get{ return _Address1;} set{_Address1 = value;} }
		public String Address2{	get{ return _Address2;} set{_Address2 = value;} }
		public String CompanyName{	get{ return _CompanyName;} set{_CompanyName = value;} }
		public String Mobile{	get{ return _Mobile;} set{_Mobile = value;} }
		public String District{	get{ return _District;} set{_District = value;} }
		public String City{	get{ return _City;} set{_City = value;} }
		public String Country{	get{ return _Country;} set{_Country = value;} }
		public String Sex{	get{ return _Sex;} set{_Sex = value;} }
		public Int32 Score{	get{ return _Score;} set{_Score = value;} }
		public String Postcode{	get{ return _Postcode;} set{_Postcode = value;} }
		
        #endregion LocalVariable
        
        #region Constructor
		public UserInfo()
		{
			_ID = 0;
			_Email = "";
			_Password = "";
			_FirstName = "";
			_LastName = "";
			_Address1 = "";
			_Address2 = "";
			_CompanyName = "";
			_Mobile = "";
			_District = "";
			_City = "";
			_Country = "";
			_Sex = "";
			_Score = 0;
			_Postcode = "";
		}
		public UserInfo(
		Int32 ID,
		String Email,
		String Password,
		String FirstName,
		String LastName,
		String Address1,
		String Address2,
		String CompanyName,
		String Mobile,
		String District,
		String City,
		String Country,
		String Sex,
		Int32 Score,
		String Postcode
		)
		{
			_ID = ID;
			_Email = Email;
			_Password = Password;
			_FirstName = FirstName;
			_LastName = LastName;
			_Address1 = Address1;
			_Address2 = Address2;
			_CompanyName = CompanyName;
			_Mobile = Mobile;
			_District = District;
			_City = City;
			_Country = Country;
			_Sex = Sex;
			_Score = Score;
			_Postcode = Postcode;
		}
		public UserInfo(DataRow dr)
		{
			if (dr != null)
			{
				_ID = dr[Field.ID.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.ID.ToString()]);
				_Email = dr[Field.Email.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Email.ToString()]);
				_Password = dr[Field.Password.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Password.ToString()]);
				_FirstName = dr[Field.FirstName.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.FirstName.ToString()]);
				_LastName = dr[Field.LastName.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.LastName.ToString()]);
				_Address1 = dr[Field.Address1.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Address1.ToString()]);
				_Address2 = dr[Field.Address2.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Address2.ToString()]);
				_CompanyName = dr[Field.CompanyName.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.CompanyName.ToString()]);
				_Mobile = dr[Field.Mobile.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Mobile.ToString()]);
				_District = dr[Field.District.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.District.ToString()]);
				_City = dr[Field.City.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.City.ToString()]);
				_Country = dr[Field.Country.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Country.ToString()]);
				_Sex = dr[Field.Sex.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Sex.ToString()]);
				_Score = dr[Field.Score.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.Score.ToString()]);
				_Postcode = dr[Field.Postcode.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Postcode.ToString()]);
			}
		}
		public UserInfo(UserInfo objEntr)
		{			
			_ID = objEntr.ID;			
			_Email = objEntr.Email;			
			_Password = objEntr.Password;			
			_FirstName = objEntr.FirstName;			
			_LastName = objEntr.LastName;			
			_Address1 = objEntr.Address1;			
			_Address2 = objEntr.Address2;			
			_CompanyName = objEntr.CompanyName;			
			_Mobile = objEntr.Mobile;			
			_District = objEntr.District;			
			_City = objEntr.City;			
			_Country = objEntr.Country;			
			_Sex = objEntr.Sex;			
			_Score = objEntr.Score;			
			_Postcode = objEntr.Postcode;			
		}
        #endregion Constructor
        
        #region InitTable
		public static DataTable ToDataTable()
		{
			DataTable dt = new DataTable("User");
			dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.ID.ToString(), typeof(Int32)),
				new DataColumn(Field.Email.ToString(), typeof(String)),
				new DataColumn(Field.Password.ToString(), typeof(String)),
				new DataColumn(Field.FirstName.ToString(), typeof(String)),
				new DataColumn(Field.LastName.ToString(), typeof(String)),
				new DataColumn(Field.Address1.ToString(), typeof(String)),
				new DataColumn(Field.Address2.ToString(), typeof(String)),
				new DataColumn(Field.CompanyName.ToString(), typeof(String)),
				new DataColumn(Field.Mobile.ToString(), typeof(String)),
				new DataColumn(Field.District.ToString(), typeof(String)),
				new DataColumn(Field.City.ToString(), typeof(String)),
				new DataColumn(Field.Country.ToString(), typeof(String)),
				new DataColumn(Field.Sex.ToString(), typeof(String)),
				new DataColumn(Field.Score.ToString(), typeof(Int32)),
				new DataColumn(Field.Postcode.ToString(), typeof(String))
			});
			return dt;
		}
		public DataRow ToDataRow(DataTable dt)
		{
			DataRow row = dt.NewRow();
			row[Field.ID.ToString()] = _ID;
			row[Field.Email.ToString()] = _Email;
			row[Field.Password.ToString()] = _Password;
			row[Field.FirstName.ToString()] = _FirstName;
			row[Field.LastName.ToString()] = _LastName;
			row[Field.Address1.ToString()] = _Address1;
			row[Field.Address2.ToString()] = _Address2;
			row[Field.CompanyName.ToString()] = _CompanyName;
			row[Field.Mobile.ToString()] = _Mobile;
			row[Field.District.ToString()] = _District;
			row[Field.City.ToString()] = _City;
			row[Field.Country.ToString()] = _Country;
			row[Field.Sex.ToString()] = _Sex;
			row[Field.Score.ToString()] = _Score;
			row[Field.Postcode.ToString()] = _Postcode;
			return row;
		}
        #endregion InitTable
    }
}
